package mysql

import "gorm.io/gorm"

type Good struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(50);not null;"`
	Cover  string  `gorm:"type:varchar(255);not null;"`
	Status string  `gorm:"type:varchar(30);not null;"`
	Stock  int64   `gorm:"type:int(10);not null;"`
	Price  float64 `gorm:"type:decimal(10,2);not null;"`
	Likes  int64   `gorm:"type:int(10);not null;"`
}

func (g *Good) Create() error {
	return DB.Create(&g).Error
}
func (g *Good) FindGood(goodId int64) error {
	return DB.Where("id = ?", goodId).First(&g).Error
}
func (g *Good) Update() error {
	return DB.Updates(&g).Error
}

type User struct {
	gorm.Model
	UserId int64  `gorm:"type:int(10);not null;"`
	Phone  string `gorm:"type:char(11);not null;"`
	Times  string `gorm:"type:varchar(50);not null;"`
	Status string `gorm:"type:varchar(30);not null;"`
}

func (u *User) FindUser(phone string) error {
	return DB.Where("phone = ?", phone).First(&u).Error
}
func (u *User) Update() error {
	return DB.Updates(&u).Error
}
